#!/bin/bash

echo "🚀 启动去中心化众筹平台 Demo"
echo "================================"

# 安装后端依赖
echo "📦 安装后端依赖..."
cd backend
npm install

# 启动后端服务
echo "🔧 启动后端API服务..."
npm start &
BACKEND_PID=$!

# 等待后端启动
sleep 3

# 启动前端服务
echo "🌐 启动前端服务..."
cd ../frontend
python3 -m http.server 8080 &
FRONTEND_PID=$!

echo "================================"
echo "✅ 启动完成！"
echo ""
echo "📍 前端地址: http://localhost:8080"
echo "📍 后端API: http://localhost:3001"
echo "📍 健康检查: http://localhost:3001/api/health"
echo ""
echo "⚠️  请确保："
echo "   1. MetaMask已安装并连接到Chain ID 88的网络"
echo "   2. 区块链节点正在 http://localhost:8545 运行"
echo ""
echo "按 Ctrl+C 停止所有服务"

# 等待中断信号
trap "echo '正在停止服务...'; kill $BACKEND_PID $FRONTEND_PID 2>/dev/null; exit" INT

# 保持脚本运行
wait